<?php $this->load->view("admin/$adminCurrentTemplate/commonHead2");?>
<table width="99%" border="0" cellspacing="1" cellpadding="0"
	class="editFormContainer">
	<form id="editForm" name="editForm" method="post" action="<?=$this->input->server('REQUEST_URI')?>">
	<input type="hidden" name="id" id="id" value="<?php if(isset($id)) echo $id; ?>" />
	<tr>
		<td class="guid">启用状态：</td>
		<td class="formItem"><input type="radio" name="disabled"
			id="disabled-0" value="0" checked="checked" /><label for="disabled-0"
			<?php if(isset($disabled)) if($disabled==0) echo ' checked' ;?>>启用</label> <input
			type="radio" name="disabled" id="disabled-1" value="1"
			<?php if(isset($disabled)) if($disabled==1) echo ' checked' ;?> /><label for="disabled-1">禁用</label>
			<span><input type="checkbox" name="childrenExtends" id="childrenExtends" value="1" /><label for="childrenExtends">子栏目继承该栏目的模板文件（封面模板、列表模板、内容模板）</label></span>
		</td>
	</tr>
	<tr>
		<td class="guid">内容模型：</td>
		<td class="formItem">
			<select size="1" name="channelId" id="channelId" class="single-select">
				<?php 
				$str = '';
				foreach ($channelList as $value){
					$str .= "<option value=\"".$value->id."\"";
					if($value->id==$channelId){
						$str .= " selected=\"selected\"";
					}
					$str .=">";
					$str .= $value->title."</option>\n"; 
				}
				echo $str;
				?>
			</select>
		</td>
	</tr>
	<tr>
		<td class="guid">上级栏目：</td>
		<td class="formItem">
		<select name="parentId" id="parentId" size="1" class="single-select">
			<!-- <option value="0"<?php if(strlen($parentId)==0) echo " selected='selected'"?>>顶级栏目</option> --><?php 
		/*$str = '';
		foreach ($categoryAll as $value){
			$str .= "<option value=\"".$value->id."\"";
			if($value->id==$parentId){
				$str .= " selected=\"selected\"";
			}
			$str .=">";
			for($i=0;$i<$value->deep;$i++){
				$str .= "&nbsp;|-";
			}
			$str .= $value->title."</option>\n";
		}
		echo $str;*/
		?></select></td>
	</tr>
	<tr>
		<td class="guid">栏目属性：</td>
		<td class="formItem">
			<select size="1" name="attribute" id="attribute" class="single-select">
				<option value="0"<?php if(isset($attribute)) if($attribute=='0' && strlen($disabled)>0) echo ' selected'?>>最终列表</option>
				<option value="1"<?php if(isset($attribute)) if($attribute=='1') echo ' selected'?>>频道封面</option>
				<option value="2"<?php if(isset($attribute)) if($attribute=='2') echo ' selected'?>>外部链接</option>
			</select>			
		</td>
	</tr>
	<tr>
		<td class="guid">排序索引：</td>
		<td class="formItem"><input type="text" name="oIndex" id="oIndex" class="sing-line input-name" value="<?php if(isset($oIndex)) echo $oIndex;?>" /></td>
	</tr>
	<tr>
		<td class="guid">栏目名称：</td>
		<td class="formItem"><input type="text" name="title" id="title"
			class="sing-line input-name" value="<?php if(isset($title)) echo $title;?>" /></td>
	</tr>	
	<tr>
		<td class="guid">SEO标题：</td>
		<td class="formItem"><input type="text" name="seotitle" id="seotitle"
			class="sing-line input-name" value="<?php if(isset($seotitle)) echo $seotitle;?>" /></td>
	</tr>
	<tr>
		<td class="guid">文件保存目录：</td>
		<td class="formItem">
			<table cellspadding='0' cellspacing='0' border='0' width='100%'>
				<tr>
					<td><input type="text" name="folder" id="folder" class="sing-line input-name" value="<?php if(isset($folder)) echo $folder;?>" /></td>
					<td style='width:90px;'><input type="checkbox" name='usePinYin' id='usePinYin' value='1' /><label for='usePinYin'>使用拼音</label></td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td class="guid">关 键 词：</td>
		<td class="formItem"><input type="text" name="keywords" id="keywords"
			class="sing-line input-name" value="<?php if(isset($keywords)) echo $keywords;?>" /></td>
	</tr>
	<tr>
		<td class="guid">内容摘要：</td>
		<td class="formItem"><textarea name="description" id="description" class="multi-line"><?php if(isset($description)) echo $description?></textarea></td>
	</tr>
	<tr>
		<td class="guid">封面模板：</td>
		<td class="formItem"><input type="text" name="tempIndex" id="tempIndex"
			class="sing-line input-name" value="<?php if(isset($tempIndex)) echo $tempIndex;?>" /></td>
	</tr>
	<tr>
		<td class="guid">列表模板：</td>
		<td class="formItem"><input type="text" name="tempList" id="tempList"
			class="sing-line input-name" value="<?php if(isset($tempList)) echo $tempList;?>" /></td>
	</tr>
	<tr>
		<td class="guid">内容模板：</td>
		<td class="formItem"><input type="text" name="tempArticle" id="tempArticle"
			class="sing-line input-name" value="<?php if(isset($tempArticle)) echo $tempArticle;?>" /></td>
	</tr>
	<tr>
      <td class="guid">栏目内容：</td>
      <td class="formItem"><?php echo $this->CKEditor->editor("content", $content);?></td>
    </tr>
	</form>
</table>
<?php $this->load->view("admin/$adminCurrentTemplate/commonFoot2");?>
<script type="text/javascript">
var tvName = '<?php if(isset($tvName)) echo $tvName;?>';
$(function(){
	$('#title').bind('blur',titleBlur);
	dg.addBtn('subBtn','提 交',subForm);
	if($('#id').val().length!=0){
		$('#parentId option[value="' + $('#id').val() + '"]').remove();
	}else{
		dg.SetTitle('添加网站栏目');
	}
	$('#channelId').bind('change',channelChange).change();
	//$('#parentId').bind('change',parentChange).change();
})

var titleBlur = function(){
	var id = $.trim($('#id').val());
	var title = $.trim($('#title').val());
	var channelId = $('#channelId').val();
	var parentId = $('#parentId').val();
	$.ajax({
		type:'POST',
		url:getInfo + '/check/',
		data:'tvName=' + tvName + '&fieldName=title&fieldValue=' + title + '&channelId=' + channelId + '&parentId=' + parentId + '&id=' + id,
		success:function(returnValue){
			if(parseInt(returnValue)>0){
				subMess(218,108,'名称错误','<span class="red">对不起，栏目名称已经存在！</span>',$("#title"));
				return false;
			}
		}
	});
}

var channelChange = function(){
	var id = $('#id').val();
	var thisValue = $(this).val();
	var parentId = $('#parentId').val();
	$.ajax({
		type:'POST',
		url:getInfo + '/categoryChannelChange/',
		data:'tvName=' + tvName + '&channelId=' + thisValue + '&parentId=' + parentId + '&id=' + id,
		success:function(returnValue){
			if($.trim(returnValue).length>0){
				$('#parentId').html(returnValue).bind('change',parentChange).change();
			}
		}
	});
}

var parentChange = function(){
	var id = $('#id').val();
	var thisValue = $(this).val();
	var channelId = $('#channelId').val();
	$.ajax({
		type:'POST',
		url:getInfo + '/categoryParentChange/',
		data:'tvName=' + tvName + '&channelId=' + channelId + '&parentId=' + thisValue + '&id=' + id,
		success:function(returnValue){
			if($.trim(returnValue).length>0)
				$('#oIndex').val(returnValue);
		}
	});
}

var subForm = function(){
	var id = $.trim($('#id').val());
	var disabled = $.trim($('#disabled').val());
	var oIndex = $.trim($('#oIndex').val());
	var channelId = $.trim($('#channelId').val());
	if(channelId.length==0){
		subMess(208,108,'内容模型错误','<span class="red">对不起，请选择内容模型！</span>',$("#channelId"));
		return false;
	}
	if(!isNumber(oIndex)){
		subMess(228,108,'排序索引错误','<span class="red">对不起，排序索引必须为数字！</span>',$("#oIndex"));
		return false;
	}
	var title = $.trim($('#title').val());
	if(title.length==0){
		subMess(208,108,'名称错误','<span class="red">对不起，请输入栏目名称！</span>',$("#title"));
		return false;
	}
	$('#editForm').submit();
}
</script>
